//
//  ALPS_AnnouncementController.m
//  Alps
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_AnnouncementController.h"
#import "WSSNetTool.h"
#import "ALPS_TListModel.h"
#import "ALPS_TListTCell.h"
#import "ALPS_TListDetailViewController.h"
#import "ALPS_TListNLDViewController.h"
#import "ALPS_TSearchViewController.h"
@implementation ALPS_AnnouncementController


- (void)dealloc
{
    _tableView.dataSource = nil;
    _tableView.delegate = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dataSource = [NSMutableArray array];
    [self getView];
    [self getData];
    [self setRightSearchButton:@selector(didSearchButton)];
    [self defaultCenterPushCollectVC];
}


//界面
-(void)getView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreeWidth, ScreeHeight - 64 - 35) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewScrollPositionNone;
    [self.view addSubview:_tableView];
    
    [self.tableView registerClass:[ALPS_TListTCell class] forCellReuseIdentifier:@"ALPS_TListTCell"];
}

//数据请求
-(void)getData
{

[WSSNetTool GetNetByURL:@"http://mobile.ximalaya.com/mobile/discovery/v2/rankingList/group?channel=ios-b1&device=iPhone&includeActivity=true&includeSpecial=true&scale=2&version=4.3.50" body:nil headers:nil response:0 success:^(id result) {
    NSArray *arr = [result objectForKey:@"datas"];
    NSArray *array = [arr[0] objectForKey:@"list"];
    for (NSDictionary *dic in array) {
        ALPS_TListModel *model = [[ALPS_TListModel alloc] initWithDic:dic];
        [self.dataSource addObject:model];
    }




    [self.tableView reloadData];
} failure:^(NSError *error) {
    
}];


}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.dataSource.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ALPS_TListTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ALPS_TListTCell"];
    cell.model = [self.dataSource objectAtIndex:indexPath.row];
    cell.selectionStyle = UITableViewCellAccessoryNone;
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //判断是否是前两个row要跳转页面
    if (indexPath.row == 1 || indexPath.row == 0) {
    ALPS_TListDetailViewController *dVC = [[ALPS_TListDetailViewController alloc] init];
    ALPS_TListModel *model = [self.dataSource objectAtIndex:indexPath.row];
    dVC.webKey = model.key;
    
    dVC.typeJudgment = model.contentType;
    dVC.navigationItem.title = model.title;
    [self.navigationController pushViewController:dVC animated:YES];
    }
    //其他row的页面跳转
    else
    {
        ALPS_TListNLDViewController *llVC = [[ALPS_TListNLDViewController alloc] init];
        ALPS_TListModel *model = [self.dataSource objectAtIndex:indexPath.row];
        llVC.webKey = model.key;
        
        llVC.typeJudgment = model.contentType;        
        llVC.navigationItem.title = model.title;
        llVC.navTitle = model.title;
        [self.navigationController pushViewController:llVC animated:YES];
    
    }

}


-(void)didSearchButton
{
    ALPS_TSearchViewController *sVC = [[ALPS_TSearchViewController alloc] init];
    
    [self.navigationController pushViewController:sVC animated:YES];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */





@end
